<?php
namespace Application\Controller;

use Application\Model\Dao\UpdateDao;
use Application\Service\XmlService;
use Zend\Authentication\AuthenticationService;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Application\Service\ImageService;
use Application\Service\UpdateService;

class DiscussionForumController extends LoginAwareController
{

    /**
     * @param $lastSeenId
     * @param $noOfItem
     */
    public function getDiscussion($lastSeenId, $noOfItems){
        $request = $this->getRequest();
        $lastSeenId = $request.getQuery('lastSeenId');
        $noOfItem = $request.getQuery('noOfItems');
        $updateDao = $this->getServiceLocator()->get('update');
        $updateDao->getUpdateData($lastSeenId, $this->getLoggedinUserId(), UpdateDao::$UPDATE_TYPE['DISCUSSION'], $noOfItem);
    }


    public function getDiscussionDetail( $discusssionId){
        $request = $this->getRequest();
        $lastSeenId = $request.getQuery('id');
        $noOfItem = $request.getQuery('noOfItems');
        $updateDao = $this->getServiceLocator()->get('update');
        $updateDao->getUpdateData($lastSeenId, $this->getLoggedinUserId(), UpdateDao::$UPDATE_TYPE['DISCUSSION'], $noOfItem);
    }

    /**
     * @return JsonModel
     * Get all discussion data.
     */
    public function saveDiscussion()
    {
        $request = $this->getRequest();
        if ($request->isPost()) {
            $discussion = $request->getPost('discussion');
            $title = $request->getPost('title');
            $targetType = $request->getPost('targetType');
            $targetId = $request->getPost('targetId');
            $photoSet = $this->getUploadedFileXml('attached');
            $loginId = $this->getLoggedinUserId();
            $updateDao =  $this->getServiceLocator()->get('update');
            $updateDao->saveUpdateData($discussion, $loginId, $photoSet, null, UpdateDao::$UPDATE_TYPE['DISCUSSION'], $targetType, $targetId);
            $data = array(
                'result' => 'success'
            );
            return new JsonModel($data);
        }
    }
}

?>